/*
Copyright (c) 2025 HeZongLun
NahidaProject is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan
PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/

#pragma once

#ifdef _WIN32
#define ExportSymbol  __declspec(dllexport)
#else
#define ExportSymbol
#endif

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <iomanip>

namespace NahidaProject {
	class ExportSymbol YAMLWriter {
	private:
		std::ofstream file;
		std::string content;
		int currentIndent;
		static const int INDENT_SIZE = 2;

		std::string FormatString(const std::string& str);
		std::string GetIndent(int level = -1);
		void AddLine(const std::string& line);

	public:
		YAMLWriter() : currentIndent(0) {}

		bool OpenFile(const std::string& filename);
		void CloseFile();
		void BeginDocument();
		void EndDocument();
		void WriteStringKeyValue(const std::string& key, const std::string& value);
		void WriteKeyValue(const std::string& key, int value);
		void WriteKeyValue(const std::string& key, double value);
		void WriteKeyValue(const std::string& key, bool value);
		void WriteArray(const std::string& key, const std::vector<std::string>& values);
		void WriteArray(const std::string& key, const std::vector<int>& values);
		void WriteArray(const std::string& key, const std::vector<double>& values);
		void WriteArray(const std::string& key, const std::vector<bool>& values);
		void BeginObject(const std::string& key = "");
		void EndObject();
		void BeginArray(const std::string& key);
		void AddArrayElement(const std::string& value);
		void AddArrayElement(int value);
		void AddArrayElement(double value);
		void AddArrayElement(bool value);
		void EndArray();
		void WriteComment(const std::string& comment);
		void WriteMultilineString(const std::string& key, const std::string& value);
		void WriteFoldedString(const std::string& key, const std::string& value);
		std::string GetContent() const;
		void Clear();
		void WriteRaw(const std::string& rawContent);
	};
}
